#pragma once
#include <cuda.h>
#include <coblas.h>

Matrix createMatrix(int m, int n, bool isColumnMajor, int offset, int pad, float* data){
	int ld = isColumnMajor ? m : n;
	ld += pad;
	int size = isColumnMajor ? n * ld : m * ld;
	size += offset;
	size *= sizeof(float);
	float *d_data;
	cudaMalloc(&d_data, size);
	cudaMemcpy(d_data, data, size, cudaMemcpyHostToDevice);
	SubMatrix m_sub(n,
                  isColumnMajor ? ld : 1,
                  d_data,
                  offset);

	Matrix M(m,
           isColumnMajor ? 1 : ld,
           m_sub);

	return M;
}

Matrix createMatrix(int m, int n, bool isColumnMajor, int offset, float* data){
	return createMatrix(m, n, isColumnMajor, offset, 0, data);
}

Vector createVector(int n, int stride, int offset, float* data){
	float *d_data;
	int size = 1 + (n - 1) * stride;
	size *= sizeof(float);
	cudaMalloc(&d_data, size);
	cudaMemcpy(d_data, data, size, cudaMemcpyHostToDevice);

	Vector v(n, stride, d_data, offset);
	return v;
}
